package com.bird.singleevent;

 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * @data 2023/4/7 22:27
 * @author: bird
 * @description: 事件发布者 发布单个事件
 * // spring的方式的事件监听器
 * https://blog.csdn.net/m0_46836425/article/details/125041306
 * https://blog.csdn.net/java123456111/article/details/124704666
 */
@Configuration
@ComponentScan(value = "com.bird")
public class PublishEvent {

    public static void main(String[] args) {
        //启动容器
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext( );
         // 将监听器添加到容器中
        applicationContext.addApplicationListener(new ListenerEventCustom());
        // 刷新容器
        applicationContext.refresh();
        //发布事件
        applicationContext.publishEvent(createEventObject());
     }

    private  static MyEventObject createEventObject(){
        Student student = new Student();
        student.setAge("18");
        student.setName("小鸟");
        student.setSex("男");
        return new MyEventObject(student);
    }

}
